package com.demo.connectdbtest.module.rest.request;

import com.fasterxml.jackson.annotation.JsonIgnore;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;
import java.io.Serializable;

/**
 * 分页基础参数
 * @author: helin @date: 2021/6/18 @Time: 19:01
 **/
@Data
public class CommonPage implements Serializable {

    private static final long serialVersionUID = -8081743138283953970L;

    @Min(value = 1, message = "页码不能小于1")
    @NotNull(message = "页码不能为空")
    @ApiModelProperty(value = "页码", required = true, example = "1")
    private Integer page = 1;

    @Min(value = 1, message = "页行数不能小于1")
    @Max(value = 100, message = "页行数不能大于100")
    @NotNull(message = "页行数不能为空")
    @ApiModelProperty(value = "页行数", required = true, example = "20")
    private Integer pageSize = 20;

    @JsonIgnore
    @ApiModelProperty(hidden = true)
    public Integer getStart() {
        Integer start = (page - 1) * pageSize;
        return start;
    }


}
